from datetime import datetime

from django.db import models


class Area(models.Model):
    name = models.CharField(max_length=50, blank=False, verbose_name="名称")

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "区域信息"
        verbose_name_plural = verbose_name


class CompanyOrg(models.Model):
    """
    企业机构消息
    """
    org_name = models.CharField('机构名称', max_length=20)
    description = models.CharField('机构描述', max_length=50)
    org_area = models.ForeignKey(Area, verbose_name='机构所属区域', on_delete=models.CASCADE, null=True, blank=True)
    parent_org = models.ForeignKey('self', verbose_name='上级机构', on_delete=models.CASCADE, null=True, blank=True)
    create_time = models.DateTimeField('创建时间', default=datetime.now)

    class Meta:
        verbose_name = "企业机构消息"
        verbose_name_plural = verbose_name
        db_table = 'company_org'

    def __str__(self):
        return self.org_name